﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using WJP.Logging;

namespace WJP.Runtime.Validation
{
    /// <summary>
    /// 应用程序验证异常
    /// </summary>
    [Serializable]
    public class AppValidationException : AppException, IHasLogLevel
    {
        /// <summary>
        /// 日志严重等级，默认为<see cref="LogLevel.Warn"/>
        /// </summary>
        public LogLevel Level { get; set; }

        /// <summary>
        /// 此异常的验证错误的详细列表
        /// </summary>
        public IList<ValidationResult> ValidationErrors { get; set; }

        public AppValidationException()
        {
            Level = LogLevel.Warn;
            ValidationErrors = new List<ValidationResult>();
        }

        /// <summary>
        /// Constructor for serializing.
        /// </summary>
        public AppValidationException(SerializationInfo serializationInfo, StreamingContext context)
            : base(serializationInfo, context)
        {
            ValidationErrors = new List<ValidationResult>();
            Level = LogLevel.Warn;
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="message">Exception message</param>
        public AppValidationException(string message)
            : base(message)
        {
            ValidationErrors = new List<ValidationResult>();
            Level = LogLevel.Warn;
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="message">Exception message</param>
        /// <param name="validationErrors">Validation errors</param>
        public AppValidationException(string message, IList<ValidationResult> validationErrors)
            : base(message)
        {
            ValidationErrors = validationErrors;
            Level = LogLevel.Warn;
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="message">Exception message</param>
        /// <param name="innerException">Inner exception</param>
        public AppValidationException(string message, Exception innerException)
            : base(message, innerException)
        {
            ValidationErrors = new List<ValidationResult>();
            Level = LogLevel.Warn;
        }
    }
}
